#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const N = 1e3 + 5;

int n, m;

inline int main() {
  cin >> n >> m;
  cout << m * (n - 1) * 2 + n * (m - 1) * 2 << '\n' << (n - 1) * 2 + (m - 1) * 2 << '\n';
  for (int i = 1; i <= n; ++i) {
    cout << i << ' ' << ((i & 1) ? 1 : m) << '\n';
  }
  for (int i = 2; i <= m; ++i) {
    cout << ((i & 1) ? n : 1) << ' ' << i << '\n';
  }
  for (int i = n - 1; i >= 1; --i) {
    cout << i << ' ' << ((i & 1) ? m : 1) << '\n';
  }
  for (int i = m - 1; i >= 1; --i) {
    cout << ((i & 1) ? 1 : n) << ' ' << i << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("find.in", "r", stdin);
  freopen("find.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
